package com.ums.scumspay.exception;

import org.apache.commons.lang3.StringUtils;

/**
 * @author sunLin
 * @description 自定义异常
 * @time 2023/3/17 10:53
 **/
public class BizException extends RuntimeException {
    BizCode bizCode;

    public BizException() {
        super(BizCode.ERROR.getDes());
    }

    public BizException(BizCode bizCode) {
        super(bizCode.getDes());
        this.bizCode = bizCode;
    }

    public BizException(BizCode bizCode, Boolean isLog) {
        super(bizCode.getDes());
        bizCode.setIsLog(isLog);
        this.bizCode = bizCode;
    }

    public BizException(BizCode errorCode, String des) {
        super(String.format("%s【%s】", errorCode.getDes(), des));
        errorCode.setMsg(des);
        this.bizCode = errorCode;
    }

    public BizException(BizCode errorCode, String des, Boolean isLog) {
        super(String.format("%s【%s】", errorCode.getDes(), des));
        errorCode.setIsLog(isLog);
        errorCode.setMsg(des);
        this.bizCode = errorCode;
    }

    public BizCode getBizErrorCode() {
        return this.bizCode;
    }

    public Boolean getBizErrorIsLog() {
        return this.bizCode.getIsLog();
    }

    public Integer getErrorCode() {
        return bizCode.getCode();
    }

    @Override
    public String getMessage() {
        if (StringUtils.isNotEmpty(bizCode.getMsg())) {
            return bizCode.getMsg();
        } else {
            return bizCode.getDes();
        }
    }
}
